#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int minNumberOfFrogs(string croakOfFrogs) {
        int c_count = 0, r_count = 0, o_count = 0, a_count = 0, k_count = 0, n = croakOfFrogs.size();
        int res = 0;
        int i = 0;
        bool flag = true;
        while (i < n)
        {
            switch (croakOfFrogs[i])
            {
            case 'c':
                ++c_count;
                if (k_count > 0) --k_count;
                break;
            case 'r':
                if (c_count > 0) ++r_count && --c_count;
                else flag = false;
                break;
            case 'o':
                if (r_count > 0) ++o_count && --r_count;
                else flag = false;
                break;
            case 'a':
                if (o_count > 0) ++a_count && --o_count;
                else flag = false;
                break;
            case 'k':
                if (a_count > 0) ++k_count && --a_count;
                else flag = false;
                if (k_count > res) res = k_count;
                break;
            default:
                flag = false;
                break;
            }
            i++;
        }
        if (c_count != 0 || r_count != 0 || o_count != 0 || a_count != 0) res = -1;
        if (flag == false) res = -1;
        return res;
    }
};